package com.mths.client.page;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.mths.client.composite.DialogBox;
import com.mths.client.i18n.UIMessages;
import com.mths.client.util.PageUtil;

public abstract class AbstractPage extends Composite {

	protected DialogBox	pagePopupDialog;

	Logger				logger		= Logger.getLogger(this.getClass().getName());
	UIMessages			messages	= GWT.create(UIMessages.class);

	public AbstractPage() {
		super();
		setPageName();
	}

	private void setPageName() {
		String pageName = pageName();
		if (pageName != null && !("").equals(pageName)) {
			PageUtil.pageName.setFieldValue(pageName);
		}
	}

	public abstract String pageName();

	public Widget popupPage(String pageName) {
		GWT.log(pageName + " page open by the popup");
		Widget openedPage = PageUtil.navigationManager.createPage(pageName);
		pagePopupDialog = new DialogBox();
		pagePopupDialog.add(openedPage);
		return openedPage;
	}

	@Override
	protected void onLoad() {
		logger.log(Level.INFO, logger.getName() + " Page loaded");
		super.onLoad();
	}

	@Override
	protected void onUnload() {
		logger.log(Level.INFO, logger.getName() + " Page unloaded");
		super.onUnload();
	}
}
